<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?>
<?php
class Myuser_helper {

	 public function __construct(){
	      parent::__construct();
	 }//endfct
    function get_userid($email){
    	$CI = &get_instance();
    	$CI->load->model('recipients_model');
    	$userid = $CI->recipients_model->get_userid($email);
    	return $userid;
    }
	public function randLetterNumber(){
		$length = 8;
		$characters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
		$string = '';
		for ($p = 0; $p < $length; $p++) {
			$string .= $characters[mt_rand(0, strlen($characters) - 1)];
		}
		return $string;
	}//end fct

    function getUserData(){
    	$CI = &get_instance();
	 	$CI->load->model('users_model');
		return $CI->users_model->get_user();
    }

    function getUserRecipients(){
    	return $this->recipients_model->getRecipients();
    }
	
	function getExecutorProfiler($userId){
    	return $this->recipients_model->executorProfiler($userId);
    }

	function getRecipients( $messageid ){
		$CI = &get_instance();
	 	$CI->load->model('recipients_model');
	 	return $CI->recipients_model->getMsgRecipients($messageid);
	}

	function countMsg($type='photos'){
		$CI = &get_instance();
		$CI->load->model('messages_model');
		return $CI->messages_model->countMessages($type);
	}

	function getFiles( $messageid ){
		$CI = &get_instance();
	 	$CI->db->where('messageid',$messageid);
	 	$files = $CI->db->get('mlme_messages_files_x');
	 	return $files->result();
	}

	// Gets random ads
	// @param string $section : sidebar; bottom
	// @param int limit
	function getAds($section='sidebar', $limit=2){
		$CI = &get_instance();
		$query = $CI->db->query("SELECT * FROM mlme_advertisements WHERE section = '".$section."' AND status = 1 ORDER BY rand() LIMIT $limit ");
		return ($limit == 1)? $query->row():$query->result();
	}//end fct

	function getFullName( $id=null ){
		if(empty($id)) return false;
		$CI = &get_instance();
		$CI->load->model('users_model','',TRUE);
		$qry = $CI->users_model->getFullname( $id );
		if( !$qry->num_rows == 1 ){
			return false;
		}
		$user = $qry->result();
		$last = ($user[0]->lastname) ? ucfirst($user[0]->lastname). ', ': ucfirst($user[0]->lastname);
		$mid = ($user[0]->middle) ? ucfirst(substr($user[0]->middle,0,1)). '.': '';
		return $last.ucfirst($user[0]->firstname).' '.$mid;

	}//end fct
	// Get user type : vip,free or reseller
	// @param user's email
	function get_user_type($email){
		$CI = &get_instance();
		$CI->load->model('users_model');
		return $CI->users_model->get_user_type($email);

	}//end fct
	function get_freeuser_messages($info,$specific=false,$userid=''){
		$CI = &get_instance();
		$CI->load->model('users_model');
		return $CI->users_model->get_freeuser_messages($info,$specific,$userid);
	}//end if
	function get_recipient_user_id($email){
		$CI = &get_instance();
		$CI->load->model('users_model');
		return $CI->users_model->get_recipient_user_id($email);
	}
	function get_post_birth_death_date($post_id){
		$CI = &get_instance();
		$CI->load->model('posts_model');
		return $CI->posts_model->get_post_birth_death_date($post_id);
	}//end fct

}/*eend of class*/
